<?php
class DistritosController extends AppController {

	var $name = 'Distritos';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->Distrito->recursive = 0;
		$this->set('distritos', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->flash(__('Invalid Distrito', true), array('action'=>'index'));
		}
		$this->set('distrito', $this->Distrito->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Distrito->create();
			if ($this->Distrito->save($this->data)) {
				$this->flash(__('Distrito saved.', true), array('action'=>'index'));
			} else {
			}
		}
		$cantones = $this->Distrito->Cantone->find('list', array('fields' => 'nombre'));
		$this->set(compact('cantones'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->flash(__('Invalid Distrito', true), array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Distrito->save($this->data)) {
				$this->flash(__('The Distrito has been saved.', true), array('action'=>'index'));
			} else {
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Distrito->read(null, $id);
		}
		$cantones = $this->Distrito->Cantone->find('list', array('fields' => 'nombre'));
		$this->set(compact('cantones'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->flash(__('Invalid Distrito', true), array('action'=>'index'));
		}
		if ($this->Distrito->del($id)) {
			$this->flash(__('Distrito deleted', true), array('action'=>'index'));
		}
	}

}
?>